<?php							
		class CArticles extends database
		{
			var $table = 'cdb_articles';
			
			
		
			public function CArticlesList ($numOfNews = -1)
			{
				$sql = "select * from {$this->table} where ID <> 1"	;
				$this->setQuery($sql);
				$this->query();
				$arrTemp =  $this->loadAllRow();
				
				
				$arr = $this->loadAllRow();
				
				$numOfRow = mysql_affected_rows();
				
				if($numOfRow<=0)
					return -1;
	
					
					
					
				$count = 1  ; 
				$arrRes = array();
				if($numOfNews != -1 )
				{
					foreach ($arrTemp as $key => $value)
					{
						$arrRes[] = $value;
						$count++;
						if($count > $numOfNews )
							return $arrRes;
					}
				}
	
				return $arrRes; 
			}
			
			
			
			public function CArticlesDetail ($id)
			{
				$sql="select * from $this->table where id='{$id}'";
				$this->setQuery($sql);
				$this->query();
				$arr=$this->loadAllRow();
				
				return $arr[0];
			}
			
			
			
			public function CArticlesAdd ($id_author,$title,$content,$picture,$source,$dateposted,$numofview,$status)
			{
				$sql = "INSERT INTO {$this->table} (`id_author`,`title`,`content`,`picture`,`source`,`dateposted`,`numofview`,`status`)
	VALUES ('{$id_author}','{$title}','{$content}','{$picture}','{$source}','{$dateposted}','{$numofview}','{$status}');";
				
				$this->setQuery($sql);
				$this->query();	

				return mysql_affected_rows();
				
			}
			
			public function CArticlesUpdate ($id,$id_author,$title,$content,$picture,$source,$dateposted,$numofview,$status)
			{
				$sql = "update $this->table set id ='{$id}',id_author ='{$id_author}',title ='{$title}',content ='{$content}',picture ='{$picture}',source ='{$source}',dateposted ='{$dateposted}',numofview ='{$numofview}',status ='{$status}' where id = '{$id}' ";
			
				$this->setQuery($sql);
				$this->query();
			}
			
			public function CArticlesDelete($id)
			{
				$sql="Delete from  $this->table where id='{$id}'";
				$this->setQuery($sql);
				$this->query();
			}
			
		}
	
	?>